<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');

	class m_AdminVendors extends CI_Model
	{
		function __construct()
    	{
    	    // Call the Model constructor
    	    parent::__construct();
    	}
		
		function get_vendors()
		{
			$this->load->database();
			$this->load->library('Datatables'); 
			$this->datatables->select('tblVendorNames.Vendor_ID, tblVendorNames.Vendor_Name, tblVendorUser.userEmail, tblVendorSources.Vendor_Source, tblVendorUser.userStatus')->from('tblVendorNames')->join('tblVendorAddresses', 'tblVendorNames.Vendor_ID = tblVendorAddresses.Vendor_ID')->join('tblVendorSources', 'tblVendorNames.Vendor_ID = tblVendorSources.Vendor_ID')->join('tblVendorUser', 'tblVendorNames.Vendor_ID = tblVendorUser.userId');
			$query = $this->datatables->generate();
			return $query;
		}
		
		function set_vendorid($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'Vendor_ID' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorAddresses', $data);
			
			$data = array(
						   'Vendor_ID' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorNames', $data); 
			
			$data = array(
						   'Vendor_ID' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorSources', $data);
			
			$data = array(
						   'Vendor_ID' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorLinks', $data);
			
			$data = array(
						   'userId' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblVendorUser', $data); 
		}
		
		function set_vendorname($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'Vendor_Name' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorNames', $data); 
		}
		
		function set_email($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'userEmail' => $value
						);

			$this->db->where('userId', $key);
			$this->db->update('tblVendorUser', $data); 
		}
		
		function set_sources($value, $key)
		{
			$this->load->database();
			
			$data = array(
						   'Vendor_Source' => $value
						);

			$this->db->where('Vendor_ID', $key);
			$this->db->update('tblVendorSources', $data); 
		}
		
		function updateclosed($closed, $Vendor_ID)
		{
			$this->load->database();
			
			$data = array(
						   'userStatus' => $closed
						);

			$this->db->where('userId', $Vendor_ID);
			$this->db->update('tblVendorUser', $data); 
		}
	}
?>
